package com.jianbing.shasha.service.impl;


import java.util.Collections;
import java.util.List;

import com.jianbing.shasha.constant.ShashaLevelConstant;
import com.jianbing.shasha.mapper.ShashaPart5RecordMapper;
import com.jianbing.shasha.mapper.ShashaUserRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jianbing.shasha.mapper.ShashaPart5QuesMapper;
import com.jianbing.shasha.domain.ShashaPart5Ques;
import com.jianbing.shasha.service.IShashaPart5QuesService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-16
 */
@Service
public class ShashaPart5QuesServiceImpl implements IShashaPart5QuesService 
{
    @Autowired
    private ShashaPart5QuesMapper shashaPart5QuesMapper;
    @Autowired
    private ShashaPart5RecordMapper shashaPart5RecordMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public ShashaPart5Ques selectShashaPart5QuesById(Long id)
    {
        return shashaPart5QuesMapper.selectShashaPart5QuesById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param shashaPart5Ques 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<ShashaPart5Ques> selectShashaPart5QuesList(ShashaPart5Ques shashaPart5Ques)
    {
        return shashaPart5QuesMapper.selectShashaPart5QuesList(shashaPart5Ques);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param shashaPart5Ques 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertShashaPart5Ques(ShashaPart5Ques shashaPart5Ques)
    {
        return shashaPart5QuesMapper.insertShashaPart5Ques(shashaPart5Ques);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param shashaPart5Ques 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateShashaPart5Ques(ShashaPart5Ques shashaPart5Ques)
    {
        return shashaPart5QuesMapper.updateShashaPart5Ques(shashaPart5Ques);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteShashaPart5QuesByIds(Long[] ids)
    {
        return shashaPart5QuesMapper.deleteShashaPart5QuesByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteShashaPart5QuesById(Long id)
    {
        return shashaPart5QuesMapper.deleteShashaPart5QuesById(id);
    }

    @Override
    public ShashaPart5Ques getQuesNotPlayByUserId(Long userId) {
        List<Long> quesPlayed = shashaPart5RecordMapper.selectQuesPlayed(userId);
        Long id = null;
        if(quesPlayed.size()>= ShashaLevelConstant.getLevelNum()){
            List<Long> allQuesId = shashaPart5QuesMapper.getAllId();
            allQuesId.removeAll(quesPlayed);
            if(allQuesId.isEmpty()){
                return null;
            }
            Collections.shuffle(allQuesId);
            id = allQuesId.get(0);
        } else {
            id = shashaPart5QuesMapper.selectByEmotionType(ShashaLevelConstant.getLevel(quesPlayed.size() + 1));
        }
        return shashaPart5QuesMapper.selectShashaPart5QuesById(id);
    }
}
